from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, PasswordField, BooleanField
from wtforms.validators import DataRequired, length, Email, EqualTo
from flask_ckeditor import CKEditorField


class Login_form(FlaskForm):
    """
    用于生成普通用户登录表单
    """
    username = StringField("用户名",
                           validators=[DataRequired(message=u'用户名不能为空'), length(3, 14, message="用户名长度应该在3到14个字符之间")])
    password = PasswordField('密码', validators=[DataRequired(message=u'密码不能为空'), length(6, 20, message="密码长度应该在6到20之间")])
    remember = BooleanField('记住我')
    submit = SubmitField('登录')


class Register_form(FlaskForm):
    """
    用户生成注册表单
    """
    email = StringField('邮箱', validators=[Email(message="邮箱格式错误"), DataRequired()])
    username = StringField("用户名",
                           validators=[DataRequired(message=u'用户名不能为空'), length(3, 14, message="用户名长度应该在3到14个字符之间")])
    password = PasswordField('密码', validators=[DataRequired(message=u'密码不能为空'), length(6, 20, message="密码长度应该在6到20之间")])
    confirm = PasswordField('重复密码', validators=[EqualTo('password', message='密码于之前填写的不符')])
    submit = SubmitField('注册')


class EditorForm(FlaskForm):
    '''
    用户生成富文本编辑器表单
    '''
    title = StringField('标题', validators=[DataRequired(), length(1, 50)])
    body = CKEditorField("正文", validators=[DataRequired()])
    submit = SubmitField('提交')


class Edit_user_form(FlaskForm):
    """
    用于生成修改用户信息的表单
    """
    username = StringField("新用户名",
                           validators=[DataRequired(message=u'用户名不能为空'), length(3, 14, message="用户名长度应该在3到14个字符之间")])
    password = PasswordField('新密码',
                             validators=[DataRequired(message=u'密码不能为空'), length(6, 20, message="密码长度应该在6到20之间")])
    email = StringField('新邮箱', validators=[Email(message="邮箱格式错误"), DataRequired()])
    submit = SubmitField('修改')


class Admin_Login_form(FlaskForm):
    """
    用于生成管理员登录表单
    """
    username = StringField("用户名",
                           validators=[DataRequired(message=u'用户名不能为空'), length(3, 14, message="用户名长度应该在3到14个字符之间")])
    password = PasswordField('密码', validators=[DataRequired(message=u'密码不能为空'), length(6, 20, message="密码长度应该在6到20之间")])
    remember = BooleanField('记住我')
    submit = SubmitField('登录')
